﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using log4net;
using Mate.Caching;
using Mate.Comment.Service;
using Mate.Core.Enums;
using Mate.Framework.BaseController.Admin;
using Microsoft.AspNetCore.Mvc;

namespace Mate.Admin.Controllers.Comment
{
    public class CommentController : BaseController
    {
        private readonly ICommentService commentService;
        private readonly ILog log;
        private readonly ICacheManager _cache;
        public CommentController(ICommentService commentService, ICacheManager cache, ILog log)
        {
            this.log = log;
            this.commentService = commentService;
            this._cache = cache;
        }

        public IActionResult Index()
        {
            ViewBag.CommentType = EnumHelper<CommentTypeEnum>.GetValueAndDes();
            return View();
        }

        #region 获取列表
        [HttpPost]
        public IActionResult GetList(int pageIndex, int pageSize, string Key, int comment_type)
        {
            int recordCount = 0;
            var list = commentService.GetCommentList(pageIndex, pageSize, comment_type, Key, ref recordCount);
            var result = new
            {
                rows = list,
                total = recordCount
            };
            return Json(result);
        }
        #endregion

        #region 详情
        public IActionResult Detail(int id,int comment_type)
        {
            var model = commentService.GetComment(id, comment_type);
            if (model == null)
            {
                return Content("参数错误");
            }
            return View(model);
        }
        #endregion

    }
}